package connect

import (
	"database/sql"
	"log"
	config "todolist-go/src/Config"

	"github.com/go-redis/redis"
	_ "github.com/go-sql-driver/mysql"
)

//获得一个数据库的连接对象
func NewMysqlClient() *sql.DB {
	db, err := sql.Open("mysql", config.MysqlUrl)
	if err != nil {
		log.Fatal("Mysql连接失败")
	} else {
		return db
	}
	return nil
}

//获得一个Redis的连接对象
func NewRedisClient() *redis.Client {
	redisClient := redis.NewClient(&redis.Options{
		Addr:     config.RedisAddr,
		Password: config.RedisPw,
		DB:       0,
	})
	_, err := redisClient.Ping().Result()
	if err != nil {
		log.Fatal("redis连接失败，err=", err)
		return nil
	}
	return redisClient
}
